#ifndef GENOMESEGMENT_H
#define GENOMESEGMENT_H

#include <QGraphicsWidget>
#include <QGraphicsWidget>
#include <QString>
#include <QGraphicsItem>
#include <QObject>
#include <QDebug>
#include <QPointer>
#include <QRectF>
#include <QPainterPath>
#include <QPainter>
#include <QHash>
#include <QList>

class Gene;
class DynamicValue;

#include "../../visbasecollection.h"

class GenomeSegment : public VisBaseCollection//public QGraphicsWidget
{
    Q_OBJECT

public:
    explicit GenomeSegment( QGraphicsItem *parent = 0);
    ~GenomeSegment();

    void addGene( QString geneId, int start, int stop, bool posStrand );
    void addGene( QString geneId, int start, int stop, bool posStrand, QString geneLineOfText, QString fileType );
    int getNTInGenomeSegment(); //returned so that, in the case with multiple genome segments,
                            //you will be able to know

    //modify appearance
    void setHeight( float newHeight );
    void setWidth( float newWidth );
    void layoutGenes();

    //connection functions
    void forgeConnection( GenomeSegment* other );
    void addConnection( QString geneId, Gene* gene );

    //alignment functions - called by child genes
    void setDistToMove( QPoint dtm );
    void setFlip( bool f, QPointF rotationPt );

    //movement functions
    //void advance();

    //draw functions
    QRectF boundingRect() const;
    QPainterPath shape() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
               QWidget *widget);

    QColor backgroundColor;
    int minNT;//these are public because child gene needs to access in flip
    int maxNT;

    void setSelectedGene(QString geneId);
    void setSelectedCluster(QString clusterId);
    QStringList getSelectedGenes();
    QStringList getSelectedClusters();
    bool containsCluster(QString clusterId );

signals:
    void throwAlignmentEvent( QString geneToAlignAgainst, QPointF posInWidget, int direction );

public slots:
    void hoverEnterEvent(QGraphicsSceneHoverEvent *event);//here make sure this contig drawn on top
    void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);  // so label can show properly

    void catchAlignmentEvent( QString geneToAlignAgainst, QPointF posInWidget, int direction );

private:
    QList< QPointer<Gene> > genes;//genes in segment currently on display
    QHash< QString, QPointer<Gene> > geneHash;

    int ntInGenomeSegment; //this stores how 'long' in nucleotides a contig is
                        //need this to scale all the contigs display of genes appropriately

    float height;
    float width;


    //  will remove these soon
    //alignment calculation variables
    QPoint distToMove;
    QPointF rotationPt;
    bool flip;

    bool updated; //handles when movement should take place

    bool hovering;

    void parseGeneLineOfText( int idx,  QString geneLineOfText, QString fileType );//this function parses
                                                                                    //extra information about a gene                                                                                    //and adds it to the gene
    float map( float valA, float aMin, float aMax, float bMin, float bMax ); //map from one range to another

    QStringList selectedGenes;
    QStringList selectedClusters; //this is a list of cluster ids that have been selected (the cd hit output)
};

#endif // GENOMESEGMENT_H
